package uml.example;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class GUI extends JFrame {
	public GUI(){}
	private JPanel contentPane;
	private JPanel DisplayPanel = new JPanel();
	private JPanel buttonPanel = new JPanel();
	private JTextField displayField = new JTextField();
	private JButton[] button = new JButton[20];
	private String[] buttonName = {"C", "M+", "M-", "MR",
								"7", "8", "9", "/",
								"4", "5", "6", "*",
								"1", "2", "3", "-",
								"0", ".", "=", "+"}; 
	//Khoi tao GUI
	public void initGUI(EventProcessor eventProcessor){
		//Lấy nội dung  để thiết lập Panel
		contentPane = (JPanel)this.getContentPane();
		contentPane.setLayout(new BorderLayout());
		
		this.setSize(new Dimension(400, 300));
		this.setTitle("AQ Calculator");
		
		//Khởi tạo DisplayPanel
		displayField.setHorizontalAlignment(SwingConstants.RIGHT);
		displayField.setColumns(32);
		displayField.setEditable(false);
		DisplayPanel.add(displayField);
				
		//Khởi tạo BtnPanel
		buttonPanel.setLayout(new GridLayout(5, 4));
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 4; j++) {
				int p = i*4+j;
				button[p]=new JButton(buttonName[p]);
				buttonPanel.add(button[p]);
				button[p].addActionListener(eventProcessor);
			}
		}
		//Sắp xếp ContentPane
		contentPane.add(DisplayPanel, BorderLayout.NORTH);
		contentPane.add(buttonPanel, BorderLayout.CENTER);
		//Khoi tao tinh toan
		eventProcessor.initCalculation();
	
	}
	
	// khoi tao gia tri cua Disp;ayFild
	public void setDisplayField(String val){
		displayField.setText(val);		
	}
	
	public String getDisplayFieldText(){
		return displayField.getText();
	}

	

}
